<template>
  <div class="header">
    <div class="header-abs">
      <router-link tag="div" to="/" v-show="showAbs">
      <div class="iconfont detail-icon">&#xe6db;</div>
      </router-link>
      <div class="detail-header" v-show="!showAbs" :style="opacityStyle">
        <router-link to="/">
          <div class="iconfont detail-fixed-icon">&#xe6db;</div>
        </router-link>
        景点详情
      </div>
    </div>
    <div class="header-fixed"></div>
  </div>
</template>

<script>
  export default {
    name:'DetailHeader',
    data() {
      return {
        showAbs:true,
        opacityStyle:{
          opacity:0
        }
      }
    },
    methods: {
      handleScroll(){
        const top=document.documentElement.scrollTop
        //console.log(top);
        if (top>60) {
          let opacity=top/140
          opacity=opacity>1?1:opacity
          this.opacityStyle={ opacity }
          this.showAbs=false
        } else{
          this.showAbs=true
        }
      }
    },
    activated() {
      window.addEventListener('scroll',this.handleScroll)
    },
    deactivated() {
      window.removeEventListener('scroll',this.handleScroll)
    },
  }
</script>

<style lang='stylus' scoped>
  //@import '~common/styles/test'
  //@import 'test.styl'
  $bHeight=.86rem
  .header-abs
    position absolute
    left .2rem
    top .2rem
    width .8rem
    height .8rem
    line-height .8rem
    border-radius .4rem
    text-align center
    background rgba(0,0,0,.8)
    .detail-icon
      //width .64rem
      font-size .6rem
      color #fff
  .detail-header
    z-index 2
    position fixed
    top 0
    left 0
    width 100%
    //overflow hidden
    height $bHeight
    line-height $bHeight
    text-align center
    background #00bcd4
    //background $bgColor
    color #fff
    font-size .32rem
    .detail-fixed-icon
      position absolute
      top 0
      left 0
      width .64rem
      text-align center
      font-size .4rem
      color #fff
</style>